package monocle.openinnitterpublic

import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.TextView

class MainActivity : PreferenceActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        LinearLayout(this)
            .apply {
                orientation = LinearLayout.VERTICAL
                Service.values().forEach { service ->
                    TextView(context).apply {
                        text = getString(R.string.node_label, service.name)
                    }.also { addView(it) }
                    val editText = EditText(context).apply {
                        setText(this@MainActivity[service])
                    }.also { addView(it) }
                    Button(context).apply {
                        setText(R.string.save_button)
                        setOnClickListener {
                            this@MainActivity[service] = editText.text.toString().trim()
                        }
                    }.also { addView(it) }
                }
            }
            .also { setContentView(it) }

    }
}